package com.xr.sy.modules.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xr.common.service.impl.CrudServiceImpl;

import com.xr.common.utils.ConvertUtils;
import com.xr.sy.modules.business.dao.DeviceDao;
import com.xr.sy.modules.business.dto.DeviceDTO;
import com.xr.sy.modules.business.entity.DeviceEntity;
import com.xr.sy.modules.business.service.DeviceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 设备
  @since 1.0.0 2019-08-17
 */
@Service
public class DeviceServiceImpl extends CrudServiceImpl<DeviceDao, DeviceEntity, DeviceDTO> implements DeviceService {

    @Override
    public QueryWrapper<DeviceEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<DeviceEntity> wrapper = new QueryWrapper<>();
        String deviceNo = (String)params.get("deviceNo");
        String institution = (String)params.get("institution");
        String position = (String)params.get("position");
        String coordinateX = (String)params.get("coordinateX");
        String coordinateY = (String)params.get("coordinateY");
        String status = (String)params.get("status");
        String phone = (String)params.get("phone");

        wrapper.like(StringUtils.isNotBlank(deviceNo), "device_no", deviceNo);
        wrapper.like(StringUtils.isNotBlank(institution), "institution", institution);
        wrapper.like(StringUtils.isNotBlank(position), "position", position);
        wrapper.like(StringUtils.isNotBlank(coordinateX), "coordinate_x", coordinateX);
        wrapper.like(StringUtils.isNotBlank(coordinateY), "coordinate_y", coordinateY);
        wrapper.like(StringUtils.isNotBlank(status), "status", status);
        wrapper.like(StringUtils.isNotBlank(phone), "phone", phone);


        //wrapper.eq(StringUtils.isNotBlank(deviceWrong), "deviceWrong", deviceWrong);
        //wrapper.eq(StringUtils.isNotBlank(accountWrong), "accountWrong", accountWrong);


        //wrapper.orderByDesc("id");
        return wrapper;
    }

    @Override
    public List<DeviceDTO> listAll() {
        QueryWrapper<DeviceEntity> wrapper = new QueryWrapper<>();
        List<DeviceEntity> list = baseDao.selectList(wrapper);
        return ConvertUtils.sourceToTarget(list, DeviceDTO.class);
    }


}